//
// Created by 谢哲 on 2021/5/16.
//

#include <iostream>
#include <vector>
using namespace std;

class Student {
public:
    int id;
    bool removed = true;
    Student *next, *prev;
};

void insert_after(Student *val, Student *p) {
    val->next = p->next;
    val->next->prev = val;
    val->prev = p;
    p->next = val;
}

void remove_stu(Student *val) {
    val->prev->next = val->next;
    val->next->prev = val->prev;
}

int main() {
    int N;
    cin >> N;

    Student *head = new Student, *tail = new Student;
    vector<Student*> vdata(N+1, nullptr);
    head->next = tail;
    tail->prev = head;

    vdata[1] = new Student;
    vdata[1]->removed = false;
    vdata[1]->id = 1;
    insert_after(vdata[1], head);

    for (int i=2; i<=N; ++i) {
        int a, b;
        cin >> a >> b;
        vdata[i] = new Student;
        vdata[i]->removed = false;
        vdata[i]->id = i;
        if (b == 0) {
            insert_after(vdata[i], vdata[a]->prev);
        }
        else {
            insert_after(vdata[i], vdata[a]);
        }
    }

    int M;
    cin >> M;

    for (int i=0; i<M; ++i) {
        int a;
        cin >> a;
        if (vdata[a]->removed) continue;
        vdata[a]->removed = true;
        remove_stu(vdata[a]);
    }

    for (auto p = head->next; p!=tail; p=p->next) {
        cout << p->id << " ";
    }

    return 0;
}
